
#######Public Opinion Toward Black Female Political Elites#####
#####by Sydney Carr########
###Study 2 Replication Code########

####first, install relevant packages
install.packages("stargazer")
install.packages("effects")
install.packages("foreign")
install.packages("readtext")
install.packages("readr")
install.packages("clubSandwich")
install.packages("estimatr")
install.packages("modelsummary")

library(stargazer)
library(effects)
library(foreign)
library(readtext)
library(readr)
library(clubSandwich)
library(estimatr)
library(modelsummary)
##set working directory
WD <- "/Users/scarr/Documents/"
##read in the csv file
W <- read.csv(paste0(WD,"study2_JOP.csv"))

##only keep respondents who answered 1 (yes) on QID1 about consent

E <- subset(W, W$QID1 == '1')

##Dependent Variables###

##Black Woman Treatment
E$blkwomtreat_strong <- E$Q19_1
E$blkwomtreat_work <- E$Q19_2
E$blkwomtreat_cares <- E$Q19_5
E$blkwomtreat_agg <- E$Q19_6
E$blkwomtreat_vote <- E$Q19_8


#Black Man Treatment

E$blkmantreat_strong <- E$Q21_1
E$blkmantreat_work <- E$Q21_2
E$blkmantreat_cares <- E$Q21_5
E$blkmantreat_agg <- E$Q21_6
E$blkmantreat_vote <- E$Q21_8

#White Woman Treatment

E$whtwomtreat_strong <- E$Q22_1
E$whtwomtreat_work <- E$Q22_2
E$whtwomtreat_cares <- E$Q22_5
E$whtwomtreat_agg <- E$Q22_6
E$whtwomtreat_vote <- E$Q22_8

#White Man Treatment

E$whtmantreat_strong <- E$Q23_1
E$whtmantreat_work <- E$Q23_2
E$whtmantreat_cares <- E$Q23_5
E$whtmantreat_agg <- E$Q23_6
E$whtmantreat_vote <- E$Q23_8

#Control

E$control_strong <- E$Q25_1
E$control_work <- E$Q25_2
E$control_cares <- E$Q25_5
E$control_agg <- E$Q25_6
E$control_vote <- E$Q25_8

##Control Variables##

##Gender#
E$gender <- E$Q27

#Race#
E$race <- E$Q2

#Education#
E$edu <- E$Q29

#Age#
E$age <- E$Q30


##next, recode DV variables to range from 0 to 1##
#Black Woman Treatment#

E$blkwomtreat_strong <- (E$blkwomtreat_strong* (-1) + 5 ) / 4
E$blkwomtreat_work <- (E$blkwomtreat_work* (-1) + 5 ) / 4
E$blkwomtreat_cares <- (E$blkwomtreat_cares* (-1) + 5 ) / 4
E$blkwomtreat_agg <- (E$blkwomtreat_agg* (-1) + 5 ) / 4
E$blkwomtreat_vote <- (E$blkwomtreat_vote* (-1) + 5 ) / 4

#Black Man Treatment#

E$blkmantreat_strong <- (E$blkmantreat_strong* (-1) + 5 ) / 4
E$blkmantreat_work <- (E$blkmantreat_work* (-1) + 5 ) / 4
E$blkmantreat_cares <- (E$blkmantreat_cares* (-1) + 5 ) / 4
E$blkmantreat_agg <- (E$blkmantreat_agg* (-1) + 5 ) / 4
E$blkmantreat_vote <- (E$blkmantreat_vote* (-1) + 5 ) / 4

#White Woman Treatment#

E$whtwomtreat_strong <- (E$whtwomtreat_strong* (-1) + 5 ) / 4
E$whtwomtreat_work <- (E$whtwomtreat_work* (-1) + 5 ) / 4
E$whtwomtreat_cares <- (E$whtwomtreat_cares* (-1) + 5 ) / 4
E$whtwomtreat_agg <- (E$whtwomtreat_agg* (-1) + 5 ) / 4
E$whtwomtreat_vote <- (E$whtwomtreat_vote* (-1) + 5 ) / 4

#White Man Treatment#

E$whtmantreat_strong <- (E$whtmantreat_strong* (-1) + 5 ) / 4
E$whtmantreat_work <- (E$whtmantreat_work* (-1) + 5 ) / 4
E$whtmantreat_cares <- (E$whtmantreat_cares* (-1) + 5 ) / 4
E$whtmantreat_agg <- (E$whtmantreat_agg* (-1) + 5 ) / 4
E$whtmantreat_vote <- (E$whtmantreat_vote* (-1) + 5 ) / 4

###Control Condition

E$control_strong <- (E$control_strong* (-1) + 5 ) / 4
E$control_work <- (E$control_work* (-1) + 5 ) / 4
E$control_cares <- (E$control_cares* (-1) + 5 ) / 4
E$control_agg <- (E$control_agg* (-1) + 5 ) / 4
E$control_vote <- (E$control_vote* (-1) + 5 ) / 4


##Control Variables#### 
#party id

#recode on the 7 point scale, 1=republican, 0=dem
E$pid <- NA
E$pid[E$Q36==1] <- 1
E$pid[E$Q36==2] <- 2
E$pid[E$Q38==2] <- 3
E$pid[E$Q38==3] <- 4
E$pid[E$Q32==4] <- 4
E$pid[E$Q32==5] <- 4
E$pid[E$Q38==1] <- 5
E$pid[E$Q37==2] <- 6
E$pid[E$Q37==1] <- 7
E$pid <- (E$pid*(-1) + 7 ) / 6
summary(E$pid)

##Age
E$age <- as.numeric(E$age)

#Gender#
#recode so that 0= female, 1=male, non-binary and no preference= na
E$gender[E$gender == 1] <- 1
E$gender[E$gender == 2] <- 0
E$gender[E$gender == 3] <- NA
E$gender[E$gender == 4] <- NA
summary(E$gender)

#Education#
#recode so that 0= high school or less, and 1= college or more
E$edu[E$edu==1] <- 0
E$edu[E$edu==2] <- 0
E$edu[E$edu==3] <- 1
E$edu[E$edu==4] <- 1
E$edu[E$edu==5] <- 1
summary(E$edu)

#Race#
#recode so that 0= black, 1= white, everyone else= NA
#create new variable for white, and new variable for black

E$race <- as.character(E$race)

#split black and white respondents into separate variables
ls_x <- strsplit(E$race, ",")
white <- rep(0, nrow(E))
black <- rep(0, nrow(E))
for (i in seq(1,nrow(E))){
  white[i] <- ifelse("1" %in% ls_x[[i]], T, F)
  black[i] <- ifelse("2" %in% ls_x[[i]], T, F)
}

E$race_white <- white
E$race_black <- black

sum(white == T & black == T)


###Racial Resentment and Modern Sexism


##Racial Resentment##

#special favors , #1=most liberal (strongly disagree), 5= most conservative (strongly agree)

E$Q4[E$Q4 == 1] <- 1
E$Q4[E$Q4 == 2] <- 0.75
E$Q4[E$Q4 == 3] <- 0.5
E$Q4[E$Q4 == 4] <- 0.25
E$Q4[E$Q4 == 5] <- 0


#deserve
#1=most liberal (strongly agree), 5= most conservative (strongly disagree)
E$Q5[E$Q5 == 1] <- 0
E$Q5[E$Q5 == 2] <- 0.25
E$Q5[E$Q5 == 3] <- 0.5
E$Q5[E$Q5 == 4] <- 0.75
E$Q5[E$Q5 == 5] <- 1

##try harder
#1=most liberal (strongly disagree), 5= most conservative (strongly agree)
E$Q6[E$Q6 == 1] <- 1
E$Q6[E$Q6 == 2] <- 0.75
E$Q6[E$Q6 == 3] <- 0.5
E$Q6[E$Q6 == 4] <- 0.25
E$Q6[E$Q6 == 5] <- 0


##slavery/discrimination
#1= most liberal (strongly agree), 5= most conservative (strongly disagree)

E$Q7[E$Q7 == 1] <- 0
E$Q7[E$Q7 == 2] <- 0.25
E$Q7[E$Q7 == 3] <- 0.75
E$Q7[E$Q7 == 4] <- 0.5
E$Q7[E$Q7 == 5] <- 1

# Create index for racial resentment
E$special_favor <- as.numeric(E$Q4)
E$deserve <- as.numeric(E$Q5)
E$try_harder <- as.numeric(E$Q6)
E$discrimrace <- as.numeric(E$Q7)
E$racial_index <- E$special_favor + E$deserve + E$try_harder + E$discrimrace

summary(E$racial_index)

###Modern Sexism###
#want the 1s to be most sexist and 0s to be most liberal

#women discrimination
#1= strongly agree (most sexist), 0=strongly disagree (most liberal)

E$Q8[E$Q8 == 1] <- 1
E$Q8[E$Q8 == 2] <- 0.75
E$Q8[E$Q8 == 3] <- 0.5
E$Q8[E$Q8 == 4] <- 0.25
E$Q8[E$Q8 == 5] <- 0
summary(E$Q8)
table(E$Q8)

#good jobs
#1=strongly disagree (most sexist), 0-strongly agree (most liberal)
E$Q9[E$Q9 == 1] <- 0
E$Q9[E$Q9 == 2] <- 0.25
E$Q9[E$Q9 == 3] <- 0.5
E$Q9[E$Q9 == 4] <- 0.75
E$Q9[E$Q9 == 5] <- 1
summary(E$Q9)
table(E$Q9)

#women tv
#1=strongly agree (most sexist), 0=strongly disagree (most liberal)

E$Q10[E$Q10 == 1] <- 1
E$Q10[E$Q10 == 2] <- 0.75
E$Q10[E$Q10 == 3] <- 0.5
E$Q10[E$Q10 == 4] <- 0.25
E$Q10[E$Q10 == 5] <- 0
summary(E$Q10)

#equal wives
#1=strongly agree (most sexist), 0=strongly disagree (most liberal)

E$Q11[E$Q11 == 1] <- 1
E$Q11[E$Q11 == 2] <- 0.75
E$Q11[E$Q11 == 3] <- 0.5
E$Q11[E$Q11 == 4] <- 0.25
E$Q11[E$Q11 == 5] <- 0
summary(E$Q11)

#equal opp
#1=strongly agree (most sexist), 0=strongly disagree (most liberal)

E$Q12[E$Q12 == 1] <- 1
E$Q12[E$Q12 == 2] <- 0.75
E$Q12[E$Q12 == 3] <- 0.5
E$Q12[E$Q12 == 4] <- 0.25
E$Q12[E$Q12 == 5] <- 0
summary(E$Q12)


#anger
#1=strongly disagree (most sexist), 0-strongly agree (most liberal)
E$Q13[E$Q13 == 1] <- 0
E$Q13[E$Q13 == 2] <- 0.25
E$Q13[E$Q13 == 3] <- 0.5
E$Q13[E$Q13 == 4] <- 0.75
E$Q13[E$Q13 == 5] <- 1
summary(E$Q13)


#limits
#1=strongly disagree (most sexist), 0-strongly agree (most liberal)

E$Q14[E$Q14 == 1] <- 0
E$Q14[E$Q14 == 2] <- 0.25
E$Q14[E$Q14 == 3] <- 0.5
E$Q14[E$Q14 == 4] <- 0.75
E$Q14[E$Q14 == 5] <- 1
summary(E$Q14)

#gov
#1=strongly agree (most sexist), 0=strongly disagree (most liberal)

E$Q15[E$Q15 == 1] <- 1
E$Q15[E$Q15 == 2] <- 0.75
E$Q15[E$Q15 == 3] <- 0.5
E$Q15[E$Q15 == 4] <- 0.25
E$Q15[E$Q15 == 5] <- 0
summary(E$Q28)
table(E$Q28)


# Create index for modern sexism
E$discrimgen <- as.numeric(E$Q8)
E$good_jobs <- as.numeric(E$Q9)
E$wom_tv <- as.numeric(E$Q10)
E$equal_wives <- as.numeric(E$Q11)
E$equal_opp <- as.numeric(E$Q12)
E$anger <- as.numeric(E$Q13)
E$limits <- as.numeric(E$Q14)
E$gov <- as.numeric(E$Q15)

E$sexism_index <- E$discrimgen + E$good_jobs + E$wom_tv + E$equal_wives + E$equal_opp
+ E$anger + E$limits + E$gov

summary(E$sexism_index)

#median of sexism index= 2.25
#median of racism index= 2


###create separate modern sexism indexes 

E$modsexism_grp1 <- E$discrimgen + E$wom_tv + E$equal_wives + E$equal_opp + E$gov

summary(E$modsexism_grp1)
E$modsexism_grp2 <- E$good_jobs + E$anger + E$limits
summary(E$modsexism_grp2)


##create separate indexes according to race and gender
##vote variable


E$blk_vote <- ifelse(!is.na(E$blkwomtreat_vote),E$blkwomtreat_vote,E$blkmantreat_vote)
summary(E$blk_vote)
E$wht_vote <- ifelse(!is.na(E$whtwomtreat_vote),E$whtwomtreat_vote,E$whtmantreat_vote)


##gender

E$wom_vote <- ifelse(!is.na(E$blkwomtreat_vote),E$blkwomtreat_vote,E$whtwomtreat_vote)
E$man_vote <- ifelse(!is.na(E$blkmantreat_vote),E$blkmantreat_vote,E$whtmantreat_vote)




 ################Grouping High/Low Racial Resent/Mod Sexism: 4 groups####################

E$sexrace <- NA
#low on sexism and low on racism
E$sexrace[E$sexism_index<2.25 & E$racial_index<2] <- "1 low/low"
#high on sexism and low on racism
E$sexrace[E$sexism_index>2.24 & E$racial_index<2] <- "2 high/low"
#low on sexism and high on racism
E$sexrace[E$sexism_index<2.25 & E$racial_index>1.99] <- "3 low/high"
#high on sexism and high on racism
E$sexrace[E$sexism_index>2.24 & E$racial_index>1.99] <- "4 high/high"

###number of respondents in each category
###according to mod sexism and racial resentment
table(E$sexrace)


                      #####tests of significance##
##create a variable for vote first

E$vote <- NA
E$vote[!is.na(E$blkwomtreat_vote)] <- E$blkwomtreat_vote[!is.na(E$blkwomtreat_vote)]
E$vote[!is.na(E$blkmantreat_vote)] <- E$blkmantreat_vote[!is.na(E$blkmantreat_vote)]
E$vote[!is.na(E$whtwomtreat_vote)] <- E$whtwomtreat_vote[!is.na(E$whtwomtreat_vote)]
E$vote[!is.na(E$whtmantreat_vote)] <- E$whtmantreat_vote[!is.na(E$whtmantreat_vote)]
E$vote[!is.na(E$control_vote)] <- E$control_vote[!is.na(E$control_vote)]

##strong leader variable

E$leader <- NA
E$leader[!is.na(E$blkwomtreat_strong)] <- E$blkwomtreat_strong[!is.na(E$blkwomtreat_strong)]
E$leader[!is.na(E$blkmantreat_strong)] <- E$blkmantreat_strong[!is.na(E$blkmantreat_strong)]
E$leader[!is.na(E$whtwomtreat_strong)] <- E$whtwomtreat_strong[!is.na(E$whtwomtreat_strong)]
E$leader[!is.na(E$whtmantreat_strong)] <- E$whtmantreat_strong[!is.na(E$whtmantreat_strong)]
E$leader[!is.na(E$control_strong)] <- E$control_strong[!is.na(E$control_strong)]

#strong work ethic variable
E$work <- NA
E$work[!is.na(E$blkwomtreat_work)] <- E$blkwomtreat_work[!is.na(E$blkwomtreat_work)]
E$work[!is.na(E$blkmantreat_work)] <- E$blkmantreat_work[!is.na(E$blkmantreat_work)]
E$work[!is.na(E$whtwomtreat_work)] <- E$whtwomtreat_work[!is.na(E$whtwomtreat_work)]
E$work[!is.na(E$whtmantreat_work)] <- E$whtmantreat_work[!is.na(E$whtmantreat_work)]
E$work[!is.na(E$control_work)] <- E$control_work[!is.na(E$control_work)]

#cares about people like me variable
E$cares <- NA
E$cares[!is.na(E$blkwomtreat_cares)] <- E$blkwomtreat_cares[!is.na(E$blkwomtreat_cares)]
E$cares[!is.na(E$blkmantreat_cares)] <- E$blkmantreat_cares[!is.na(E$blkmantreat_cares)]
E$cares[!is.na(E$whtwomtreat_cares)] <- E$whtwomtreat_cares[!is.na(E$whtwomtreat_cares)]
E$cares[!is.na(E$whtmantreat_cares)] <- E$whtmantreat_cares[!is.na(E$whtmantreat_cares)]
E$cares[!is.na(E$control_cares)] <- E$control_cares[!is.na(E$control_cares)]

#aggressive variable

E$agg <- NA
E$agg[!is.na(E$blkwomtreat_agg)] <- E$blkwomtreat_agg[!is.na(E$blkwomtreat_agg)]
E$agg[!is.na(E$blkmantreat_agg)] <- E$blkmantreat_agg[!is.na(E$blkmantreat_agg)]
E$agg[!is.na(E$whtwomtreat_agg)] <- E$whtwomtreat_agg[!is.na(E$whtwomtreat_agg)]
E$agg[!is.na(E$whtmantreat_agg)] <- E$whtmantreat_agg[!is.na(E$whtmantreat_agg)]
E$agg[!is.na(E$control_agg)] <- E$control_agg[!is.na(E$control_agg)]


##need to next make a variable for treatment

E$treat <- NA
E$treat[!is.na(E$blkwomtreat_vote)] <- " 1 blkwom"
E$treat[!is.na(E$blkmantreat_vote)] <- "2 blkman"
E$treat[!is.na(E$whtwomtreat_vote)] <- "3 whtwom"
E$treat[!is.na(E$whtmantreat_vote)] <- "4 whtman"
E$treat[!is.na(E$control_vote)] <- "5 control"

##strong leadership
E$treat_leader <- NA
E$treat_leader[!is.na(E$blkwomtreat_leader)] <- " 1 blkwom"
E$treat_leader[!is.na(E$blkmantreat_leader)] <- " 2 blkman"
E$treat_leader[!is.na(E$whtwomtreat_leader)] <- "3 whtwom"
E$treat_leader[!is.na(E$whtmantreat_leader)] <- "4 whtman"
E$treat_leader[!is.na(E$control_leader)] <- "5 control"

##strong work ethic
E$treat_work <- NA
E$treat_work[!is.na(E$blkwomtreat_work)] <- " 1 blkwom"
E$treat_work[!is.na(E$blkmantreat_work)] <- " 2 blkman"
E$treat_work[!is.na(E$whtwomtreat_work)] <- "3 whtwom"
E$treat_work[!is.na(E$whtmantreat_work)] <- "4 whtman"
E$treat_work[!is.na(E$control_work)] <- "5 control"

##cares about people like me
E$treat_cares <- NA
E$treat_cares[!is.na(E$blkwomtreat_cares)] <- " 1 blkwom"
E$treat_cares[!is.na(E$blkmantreat_cares)] <- " 2 blkman"
E$treat_cares[!is.na(E$whtwomtreat_cares)] <- "3 whtwom"
E$treat_cares[!is.na(E$whtmantreat_cares)] <- "4 whtman"
E$treat_cares[!is.na(E$control_cares)] <- "5 control"

##aggressive
E$treat_agg <- NA
E$treat_agg[!is.na(E$blkwomtreat_agg)] <- " 1 blkwom"
E$treat_agg[!is.na(E$blkmantreat_agg)] <- " 2 blkman"
E$treat_agg[!is.na(E$whtwomtreat_agg)] <- "3 whtwom"
E$treat_agg[!is.na(E$whtmantreat_agg)] <- "4 whtman"
E$treat_agg[!is.na(E$control_agg)] <- "5 control"


                   ################Regression Models###############

##willigness to vote variable
mod_vote <- lm(vote ~  sexrace*treat + pid*treat + race_white + gender, 
               data = E)

summary(mod_vote)


##strong leader characteristic

mod_leader <- lm(leader ~ sexrace*treat + pid*treat + race_white + gender, 
               data = E)

summary(mod_leader)

##strong work ethic characteristic

mod_work <- lm(work ~ sexrace*treat_work + pid*treat_work + race_white + gender, 
                  data = E)

summary(mod_work)


#cares about people like me characteristic

mod_cares <- lm(cares ~ sexrace*treat_cares + pid*treat_cares + race_white + gender, 
                  data = E)

summary(mod_cares)


#aggressive characteristic

mod_agg <- lm(agg ~ sexrace*treat_agg + pid*treat_agg + race_white + gender, 
                  data = E)

summary(mod_agg)


#####################Create Tables for Study 2 in Appendix: Tables 2.1, 2.2, 2.3, 2.4, and 2.5########
#############create the tables to output to an html using stargazer#############
#########for the purposes of the paper, the tables here were then converted into word doc tables#######
####these html files will output onto laptop/computer####
####Table 2.1 (Appendix)
###vote####
stargazer(
  mod_vote,
  type = "html",
  align = TRUE,
  dep.var.labels=c("Willingess to Vote"),
  covariate.labels = c(
    "high on mod sexism * low on racial resent", "low on mod sexism * high on racial resent",
    "high on mod sexism * high on racial resent", "Black Male Treatment", 
    "White Female Treatment", "White Male Treatment", "Control", "Party ID(Democrat)", "Race(White)",
    "Gender(Men)", 
    "high on mod sexism/low on racial resent * Black Male Political Figures", 
    "low on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/low on racial resent * White Female Political Figures", 
    "low on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/low on racial resent * White Male Political Figures", 
    "low on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/low on racial resent * Control", 
    "low on mod sexism/high on racial resent * Control", 
    "high on mod sexism/high on racial resent * Control", 
    "Black Male Political Figures * Party ID (Democrat)",
    "White Female Political Figures * Party ID (Democrat)",
    "White Male Political Figures * Party ID(Democrat)",
    "Control * Party ID (Democrat)"),
  omit.stat=c("LL","ser","f"), no.space=TRUE, 
  keep.stat = c("n", "rsq", "adj.rsq"),
  title = "Study 2: Willingess to Vote", out = "study2_vote.html")

##Table 2.2 (Appendix)
###strong leader####
stargazer(
  mod_leader,
  type = "html",
  align = TRUE,
  dep.var.labels=c("Strong Leadership"),
  covariate.labels = c(
    "high on mod sexism * low on racial resent", "low on mod sexism * high on racial resent",
    "high on mod sexism * high on racial resent", "Black Male Treatment", 
    "White Female Treatment", "White Male Treatment", "Control", "Party ID(Democrat)", "Race(White)",
    "Gender(Men)", 
    "high on mod sexism/low on racial resent * Black Male Political Figures", 
    "low on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/low on racial resent * White Female Political Figures", 
    "low on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/low on racial resent * White Male Political Figures", 
    "low on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/low on racial resent * Control", 
    "low on mod sexism/high on racial resent * Control", 
    "high on mod sexism/high on racial resent * Control", 
    "Black Male Political Figures * Party ID (Democrat)",
    "White Female Political Figures * Party ID (Democrat)",
    "White Male Political Figures * Party ID(Democrat)",
    "Control * Party ID (Democrat)"),
  omit.stat=c("LL","ser","f"), no.space=TRUE, 
  keep.stat = c("n", "rsq", "adj.rsq"),
  title = "Study 2: Strong Leadership", out = "study2_leader.html")


###Table 2.3 (Appendix)
##Strong Work Ethic Characteristic 

stargazer(
  mod_work,
  type = "html",
  align = TRUE,
  dep.var.labels=c("Strong Work Ethic"),
  covariate.labels = c(
    "high on mod sexism * low on racial resent", "low on mod sexism * high on racial resent",
    "high on mod sexism * high on racial resent", "Black Male Treatment", 
    "White Female Treatment", "White Male Treatment", "Control", "Party ID(Democrat)", "Race(White)",
    "Gender(Men)", 
    "high on mod sexism/low on racial resent * Black Male Political Figures", 
    "low on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/low on racial resent * White Female Political Figures", 
    "low on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/low on racial resent * White Male Political Figures", 
    "low on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/low on racial resent * Control", 
    "low on mod sexism/high on racial resent * Control", 
    "high on mod sexism/high on racial resent * Control", 
    "Black Male Political Figures * Party ID (Democrat)",
    "White Female Political Figures * Party ID (Democrat)",
    "White Male Political Figures * Party ID(Democrat)",
    "Control * Party ID (Democrat)"),
  omit.stat=c("LL","ser","f"), no.space=TRUE, 
  keep.stat = c("n", "rsq", "adj.rsq"),
  title = "Study 2: Strong Work Ethic", out = "study2_workethic.html")

##Table 2.4 (Appendix)
##Cares About People Like Me Characteristic
stargazer(
  mod_cares,
  type = "html",
  align = TRUE,
  dep.var.labels=c("Cares About People Like Me"),
  covariate.labels = c(
    "high on mod sexism * low on racial resent", "low on mod sexism * high on racial resent",
    "high on mod sexism * high on racial resent", "Black Male Treatment", 
    "White Female Treatment", "White Male Treatment", "Control", "Party ID(Democrat)", "Race(White)",
    "Gender(Men)", 
    "high on mod sexism/low on racial resent * Black Male Political Figures", 
    "low on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/low on racial resent * White Female Political Figures", 
    "low on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/low on racial resent * White Male Political Figures", 
    "low on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/low on racial resent * Control", 
    "low on mod sexism/high on racial resent * Control", 
    "high on mod sexism/high on racial resent * Control", 
    "Black Male Political Figures * Party ID (Democrat)",
    "White Female Political Figures * Party ID (Democrat)",
    "White Male Political Figures * Party ID(Democrat)",
    "Control * Party ID (Democrat)"),
  omit.stat=c("LL","ser","f"), no.space=TRUE, 
  keep.stat = c("n", "rsq", "adj.rsq"),
  title = "Study 2: Cares About People Like Me", out = "study2_cares.html")

##Table 2.5 (Appendix)
##Aggressive Characteristic
stargazer(
  mod_agg,
  type = "html",
  align = TRUE,
  dep.var.labels=c("Aggressive"),
  covariate.labels = c(
    "high on mod sexism * low on racial resent", "low on mod sexism * high on racial resent",
    "high on mod sexism * high on racial resent", "Black Male Treatment", 
    "White Female Treatment", "White Male Treatment", "Control", "Party ID(Democrat)", "Race(White)",
    "Gender(Men)", 
    "high on mod sexism/low on racial resent * Black Male Political Figures", 
    "low on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/high on racial resent * Black Male Political Figures", 
    "high on mod sexism/low on racial resent * White Female Political Figures", 
    "low on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/high on racial resent * White Female Political Figures", 
    "high on mod sexism/low on racial resent * White Male Political Figures", 
    "low on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/high on racial resent * White Male Political Figures", 
    "high on mod sexism/low on racial resent * Control", 
    "low on mod sexism/high on racial resent * Control", 
    "high on mod sexism/high on racial resent * Control", 
    "Black Male Political Figures * Party ID (Democrat)",
    "White Female Political Figures * Party ID (Democrat)",
    "White Male Political Figures * Party ID(Democrat)",
    "Control * Party ID (Democrat)"),
  omit.stat=c("LL","ser","f"), no.space=TRUE, 
  keep.stat = c("n", "rsq", "adj.rsq"),
  title = "Study 2: Aggressive", out = "study2_agg.html")



#########Create Figure Located in the Paper: Figure 2.1#########
################Point Estimation Figure####################
######this pdf file will output onto laptop/computer######

###Figure 2.1
##### wilingness to vote variable#####
mod_vote_bw <- lm(blkwomtreat_vote ~ sexrace + pid, data = E)
mod_vote_bm <- lm(blkmantreat_vote ~ sexrace + pid, data = E)
mod_vote_ww <- lm(whtwomtreat_vote ~ sexrace + pid, data = E)
mod_vote_wm <- lm(whtmantreat_vote ~ sexrace + pid, data = E)
modelsummary(list(mod_vote_bw, mod_vote_bm, mod_vote_ww, mod_vote_wm),
             stars=T, 
             gof_omit="IC|RMSE|F|Adj")

eff <- effect("sexrace", mod_vote_bw)
effr1 <- cbind(eff$x,fit=eff$fit,lower=eff$lower,higher=eff$upper)
eff <- effect("sexrace", mod_vote_bm)
effr2 <- cbind(eff$x,fit=eff$fit,lower=eff$lower,higher=eff$upper)
eff <- effect("sexrace", mod_vote_ww)
effr3 <- cbind(eff$x,fit=eff$fit,lower=eff$lower,higher=eff$upper)
eff <- effect("sexrace", mod_vote_wm)
effr4 <- cbind(eff$x,fit=eff$fit,lower=eff$lower,higher=eff$upper)
effr1$treatment <- "1 black women"
effr2$treatment <- "2 black men"
effr3$treatment <- "3 white women"
effr4$treatment <- "4 white men"
effr <- rbind(effr1,effr2,effr3,effr4)
effr$order <- as.numeric(substring(effr$sexrace,1,1))
effr$order2 <- NA
effr$order2[effr$treatment=="1 black women"] <- effr$order[effr$treatment=="1 black women"] - .2
effr$order2[effr$treatment=="2 black men"] <- effr$order[effr$treatment=="2 black men"] - .1
effr$order2[effr$treatment=="3 white women"] <- effr$order[effr$treatment=="3 white women"] 
effr$order2[effr$treatment=="4 white men"] <- effr$order[effr$treatment=="4 white men"] + .1

{
  pdf("study2_vote_figure.pdf", width = 6.5, height = 5.5)
  plot(effr$order, effr$fit,  type="n", ann=FALSE, axes=FALSE, ylim=c(.2,.8), xlim=c(.5,4.5))
  p <- effr[effr$treatment=="1 black women",]
  arrows(p$order2, p$lower, p$order2, p$higher, length=.05, code=3, angle=90, col="gray20",lwd=1,lty=3)
  points(p$order2, p$fit,  col="black", pch=15)
  p <- effr[effr$treatment=="2 black men",]
  arrows(p$order2, p$lower, p$order2, p$higher, length=.05, code=3, angle=90, col="gray20",lwd=1,lty=3)
  points(p$order2, p$fit,  col="black", pch=16)
  p <- effr[effr$treatment=="3 white women",]
  arrows(p$order2, p$lower, p$order2, p$higher, length=.05, code=3, angle=90, col="gray20",lwd=1,lty=3)
  points(p$order2, p$fit,  col="black", pch=17)
  p <- effr[effr$treatment=="4 white men",]
  arrows(p$order2, p$lower, p$order2, p$higher, length=.05, code=3, angle=90, col="gray20",lwd=1,lty=3)
  points(p$order2, p$fit,  col="black", pch=18)
  axis(1, at=c(1,2,3,4), labels=c("Low Sexism\nLow Racism", 
                                  "High Sexism\nLow Racism", 
                                  "Low Sexism\nHigh Racism",
                                  "High Sexism\nHigh Racism"), col="white", cex.axis=.8)
  axis(2, las=1)
  legend(3, .8, legend=c("Black Women", 
                         "Black Men", 
                         "White Women",
                         "White Men"),
         col=c("black", "black", "black", "black"), pch=c(15,16,17,18), cex=0.8, box.lty=0)
  mtext(side=1, "Respondent Sexism/Racism Categories", line=3)
  mtext(side=2, "Likelihood of Voting for Candidate", line=3)
  dev.off()
}















         



